package com.zhentao.controller;

import com.zhentao.pojo.TbForumCategory;
import com.zhentao.pojo.TbForumComment;
import com.zhentao.pojo.TbForumPost;
import com.zhentao.service.TbForumCategoryService;
import com.zhentao.service.TbForumCommentService;
import com.zhentao.service.TbForumPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("forum")
@CrossOrigin(origins = "*", maxAge = 3600)
public class ForumController {
    @Autowired
    TbForumCommentService tbForumCommentService;
    @Autowired
    TbForumCategoryService tbForumCategoryService;
    @Autowired
    TbForumPostService tbForumPostService;

    @PostMapping("ForumCommentAdd")
    public String ForumCommentAdd(@RequestBody TbForumComment tbForumComment){
         boolean i=tbForumCommentService.save(tbForumComment);
         if(i== true){
             return "添加成功";
         }else {
             return "添加失败";
         }
    }
    
    @GetMapping("ForumCommentFindall")
    public List<TbForumComment> ForumCommentFindall(){
        return tbForumCommentService.list();
    }
    
    @GetMapping("ForumCategoryFindall")
    public List<TbForumCategory> ForumCategoryFindall(){
        return tbForumCategoryService.list();
    }
    
    @GetMapping("ForumPostFindall")
    public List<TbForumPost> ForumPostFindall(){
        return tbForumPostService.list();
    }
    
    @GetMapping("ForumPostFindById/{id}")
    public TbForumPost ForumPostFindById(@PathVariable Integer id){
        return tbForumPostService.getById(id);
    }
    
    @PostMapping("ForumPostAdd")
    public String ForumPostAdd(@RequestBody TbForumPost tbForumPost){
        boolean i=tbForumPostService.save(tbForumPost);
        if(i== true){
            return "添加成功";
        }else {
            return "添加失败";
        }
    }
}
